//控制banner数据库的操作
const Banner = require("../model/banner");
const { publicPath, publicUrl } = require("../config/index");
const path = require("path");
//前台获取轮播图
exports.indexBanners = async (req, res, next) => {
  try {
    //获取轮播图数量
    let total = await Banner.find().count();
    let urlList = await Banner.find().select("url");
    urlList = urlList.map((item) => {
      return {
        _id: item._id,
        url: publicUrl + `/images/banner/${item.url}`,
      };
    });
    res.json({
      code: 200,
      data: urlList,
    });
  } catch (error) {
    console.log(error);
  }
};

